<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;

class LiveViewChange implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
    private $url;
    private $params;

    /**
     * Create a new job instance.
     *
     * @param $url
     * @param $params
     */
    public function __construct($url, $params)
    {

        $this->url    = $url;
        $this->params = $params;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $url    = $this->url;
        $params = $this->params;
        $res    = $this->post_curl($url, $params);
    }

    protected function post_curl(string $url, array $data_string)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data_string));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
                'Content - Type: application / json',
                'Content - Length: ' . strlen(json_encode($data_string))
            ]
        );
        $result = curl_exec($ch);

        return $result;
    }
}
